//
//  BIZRecruitListCell.m
//  biz
//
//  Created by LXL on 2017/6/12.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZRecruitListCell.h"
#import "BIZRecruitModel.h"
#import "BIZRecruitCollectionCell.h"

@interface BIZRecruitListCell()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (strong, nonatomic) NSMutableArray *positionArr;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewHeightLayout;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionViewWidthLayout;

@end
@implementation BIZRecruitListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setRecruitModel:(BIZRecruitModel *)recruitModel {
    _recruitModel = recruitModel;
    self.companyLabel.text = recruitModel.name;
    self.addressLabel.text = recruitModel.address;
    self.dateLabel.text = [NSDate stringFromTimestamp:recruitModel.updateDate];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerNib:[UINib nibWithNibName:@"BIZRecruitCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"BIZRecruitCollectionCell"];
    self.positionArr = [NSMutableArray arrayWithArray:recruitModel.hires];
    self.collectionViewHeightLayout.constant = 35*recruitModel.hires.count + (recruitModel.hires.count-1)*10;
    [self.collectionView reloadData];
}

- (void)reloadCell{
    [self.collectionView reloadData];
    self.collectionViewHeightLayout.constant = self.layout.collectionViewContentSize.height;
    [self updateConstraintsIfNeeded];
    if (self.delegate) {
        [self.delegate shouldReload];

    }
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.positionArr.count;
}

//呈现数据
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    BIZRecruitCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BIZRecruitCollectionCell" forIndexPath:indexPath];
    cell.positionModel = self.positionArr[indexPath.row];
    return cell;
}


//配置每个item的size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(App_Frame_Width-67, 35);
}

//配置item的边距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

//-(void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
//    
//}


//点击item时触发
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    if (self.didSelectCollectionViewItemBlock) {
        self.didSelectCollectionViewItemBlock(indexPath);
    }
}

- (NSMutableArray *)positionArr {
    if (!_positionArr) {
        _positionArr = [NSMutableArray array];
    }
    
    return _positionArr;
}

- (void)layoutSubviews {
    [super layoutSubviews];

}


@end
